package com.example.mapper;

import com.example.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectUserById(int id);

    @Update({"<script>",
            "UPDATE user",
            "<set>",
            "<if test='name != null'>name = #{name},</if>",
            "<if test='age != null'>age = #{age}</if>",
            "</set>",
            "WHERE id = #{id}",
            "</script>"})
    int updateUser(User user);

    @Delete({"<script>",
            "DELETE FROM user WHERE id IN",
            "<foreach item='item' index='index' collection='array' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    int deleteUsers(int[] ids);
}
